
var mult = function () {
    console.log("计算乘积");
    var n = 1
    for (let i = 0; i < arguments.length; i++) {
        n = n * arguments[i]
    }
    return n
}
var plus = function () {
    console.log("计算加法");
    var n = 0
    for (let i = 0; i < arguments.length; i++) {
        n = n + arguments[i]
    }
    return n
}

// 创建一个create缓存代理的函数

var createCacheFunc = function (func) {
    var cache = {}

    return function () {
        const args = Array.prototype.join.call(arguments,",")

        if(cache[args]){
            return cache[args]
        }

        return cache[args] = func.apply(this,arguments)
    }
}

var multProxy = createCacheFunc(mult)
var plusProxy = createCacheFunc(plus)

console.log(multProxy(1,2,3,4));
console.log(multProxy(1,2,3,4));
console.log(plusProxy(1,2,3,5));
console.log(plusProxy(1,2,3,5));